//
//  SubmitFeedBackViewController.m
//  qdSubway
//
//  Created by andi911 on 2019/5/30.
//  Copyright © 2019 andi911. All rights reserved.
//

#import "SubmitFeedBackViewController.h"

@interface SubmitFeedBackViewController ()<UITextViewDelegate>
//文本输入框
@property (nonatomic, strong)UITextView *textView;
// 提示文本
@property (nonatomic, strong)UILabel *label;
//
@property (nonatomic,strong) UIScrollView *scrollView;

@end

@implementation SubmitFeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self loadSetUpUI];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textViewEditChanged:)
                                                name:@"UITextViewTextDidChangeNotification"
                                              object:_textView];
}

- (void)loadSetUpUI{
    [self.view addSubview:self.scrollView];
    UIView *topView = [[UIView alloc]init];
    topView.width = Screen_W;
    topView.height = 100;
    topView.backgroundColor = RGB(247);
    [self.scrollView addSubview:topView];
    
    UILabel *titlteLab = [[UILabel alloc]init];
    titlteLab.width = Screen_W - 40;
    titlteLab.text = @"任务标题任务标题任务标题任务标题任务标题任务标题任务标题";
    titlteLab.height =[titlteLab.text cly_stringHeightWithFont:[UIFont boldSystemFontOfSize:18] width:titlteLab.width ];
    if (titlteLab.height>25) {
        titlteLab.numberOfLines = 2;
    }
    titlteLab.font = [UIFont boldSystemFontOfSize:18];
    titlteLab.center = CGPointMake(20+titlteLab.width/2, 25+titlteLab.height/2);
    [topView addSubview:titlteLab];
    
    UIImageView *leftImage = [[UIImageView alloc]initWithImage:CLYImage(@"left_panddIma")];
    leftImage.center = CGPointMake(leftImage.width/2, getRectNavAndStatusHight+25+leftImage.height/2);
    [topView addSubview:leftImage];
    
    NSString *str = @"说明说明进行公园广场环境保洁活动，清扫该地垃圾、杂物;保持环境卫生，进行文明游园宣传等活动多久啊空间的大大";
    UILabel *contentLab = [[UILabel alloc]init];
    contentLab.text = str;
    contentLab.width = Screen_W -40;
    contentLab.font = CLYFont(16);
    contentLab.numberOfLines = 0;
    contentLab.textColor = [UIColor grayColor];
    contentLab.height = [contentLab.text cly_stringHeightWithFont:CLYFont(16) width:contentLab.width];
    contentLab.center = CGPointMake(Screen_W/2, titlteLab.bottom+15+contentLab.height/2);
    [topView addSubview:contentLab];

    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(20, contentLab.bottom+15, Screen_W-40, 0.5)];
    line.backgroundColor = [UIColor lightGrayColor];
    [topView addSubview:line];
    
    NSArray *leftArr = @[@"领取人数",@"任务时间",@"获取积分"];
    NSArray *rightArr = @[@"10/100",@"2019-11-12至2019-12-12",@"20积分"];
    
    for (int i=0; i<3; i++) {
        UILabel *leftLabel = [[UILabel alloc]init];
        leftLabel.height = 18;
        leftLabel.font = CLYFont(16);
        leftLabel.text = leftArr[i];
        leftLabel.width = [leftLabel.text cly_stringSizeWithFont:CLYFont(16)].width;
        leftLabel.center = CGPointMake(20+leftLabel.width/2, line.bottom+15+leftLabel.height/2+(15+leftLabel.height)*i);
        [topView addSubview:leftLabel];
        
        UILabel *rightLabel = [[UILabel alloc]init];
        rightLabel.width = Screen_W-leftLabel.right-15-15;
        rightLabel.height = 18;
        rightLabel.font = CLYFont(16);
        rightLabel.textColor = [UIColor lightGrayColor];
        rightLabel.text = rightArr[i];
        rightLabel.center = CGPointMake(leftLabel.right+15+rightLabel.width/2, leftLabel.centerY);
        [topView addSubview:rightLabel];
        if(i==2){
            topView.height = leftLabel.bottom+25;
        }
    }
    
    UILabel *centerTitleLab = [[UILabel alloc]init];
    centerTitleLab.width = Screen_W - 40;
    centerTitleLab.height = 18;
    centerTitleLab.textColor = MainBtnColor;
    centerTitleLab.text = @"*请填写反馈描述 (20-200字以内)";
    centerTitleLab.center = CGPointMake(20+centerTitleLab.width/2, topView.bottom+25+centerTitleLab.height/2);
    [self.scrollView addSubview:centerTitleLab];
    [self loadTextView:centerTitleLab.bottom+12];
    
    UILabel *imageLab = [[UILabel alloc]init];
    imageLab.text = @"请上传图片";
    imageLab.font = CLYFont(16);
    imageLab.width = [imageLab.text cly_stringSizeWithFont:CLYFont(16)].width;
    imageLab.height = 16;
    imageLab.textColor = MainBtnColor;
    imageLab.center = CGPointMake(20+imageLab.width/2, _textView.bottom+25+imageLab.height/2);
    [self.scrollView addSubview:imageLab];
    
    UILabel *countImaLab = [[UILabel alloc]init];
    countImaLab.width =80;
    countImaLab.height = 16;
    countImaLab.textColor = [UIColor grayColor];
    countImaLab.center = CGPointMake(imageLab.right+countImaLab.width/2, _textView.bottom+25+imageLab.height/2);
    countImaLab.text = @"(2/3)";
    [self.scrollView addSubview:countImaLab];
    
    UIButton *addImageBtn = [[UIButton alloc]init];
    addImageBtn.width = 90;
    addImageBtn.height = 90;
    [addImageBtn addTarget:self action:@selector(tapImageBtn) forControlEvents:1<<6];
    addImageBtn.backgroundColor = [UIColor grayColor];
    addImageBtn.center = CGPointMake(20+addImageBtn.width/2, imageLab.bottom+10+addImageBtn.height/2);
    [self.scrollView addSubview:addImageBtn];
    self.scrollView.contentSize = CGSizeMake(Screen_W, addImageBtn.bottom);
    
    UIButton *bottomBtn = [[UIButton alloc]init];
    bottomBtn.width = Screen_W - 40;
    bottomBtn.height = 44;
    bottomBtn.layer.cornerRadius = 22;
    bottomBtn.layer.masksToBounds = YES;
    bottomBtn.backgroundColor = RGBACOLOR(37, 184, 66);
    [bottomBtn setTitle:@"提交反馈" forState:0];
    [bottomBtn addTarget:self action:@selector(tapsubmitBtn) forControlEvents:1<<6];
    bottomBtn.center =  CGPointMake(Screen_W/2, self.scrollView.bottom+20+bottomBtn.height/2);
    [self.view addSubview:bottomBtn];
    
}

#pragma mark ------ 点击操作 -----
- (void)tapImageBtn{
    
}

- (void)tapsubmitBtn{
    
}


- (UIScrollView *)scrollView{
    if(!_scrollView){
        UIScrollView *tempScrollView = [[UIScrollView alloc]init];
        tempScrollView.width = Screen_W;
        tempScrollView.height = Screen_H-(getRectNavAndStatusHight)-40-44;
        tempScrollView.center = CGPointMake(Screen_W/2, getRectNavAndStatusHight+tempScrollView.height/2);
        tempScrollView.scrollEnabled = YES;
//        tempScrollView.contentSize = CGSizeMake(Screen_W, Screen_H-getRectNavAndStatusHight-40-44-100);
        _scrollView = tempScrollView;
    }
    return _scrollView;
}


- (void)loadTextView:(CGFloat)startY{
    //初始化并定义大小
    _textView = [[UITextView alloc] initWithFrame:CGRectMake(20, startY, Screen_W-40, 150)];
    _textView.delegate = self;
    _textView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    _textView.layer.borderWidth = 0.5;
    _textView.backgroundColor=[UIColor whiteColor]; //背景色
    _textView.scrollEnabled = NO;    //当文字超过视图的边框时是否允许滑动，默认为“YES”
    _textView.editable = YES;        //是否允许编辑内容，默认为“YES”
    _textView.delegate = self;       //设置代理方法的实现类
    _textView.font=[UIFont fontWithName:@"Arial" size:17.0]; //设置字体名字和字体大小;
    _textView.returnKeyType = UIReturnKeyDone;//return键的类型
    _textView.keyboardType = UIKeyboardTypeDefault;//键盘类型
    _textView.textAlignment = NSTextAlignmentLeft; //文本显示的位置默认为居左
    _textView.dataDetectorTypes = UIDataDetectorTypeAll; //显示数据类型的连接模式（如电话号码、网址、地址等）
    _textView.textColor = [UIColor blackColor];
    [self.scrollView addSubview:_textView];
    _label = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 280, 21)];
    _label.font = [UIFont systemFontOfSize:17.0f];
    _label.textColor = RGBACOLOR(163, 163, 163);
    _label.text = @"简述自身工作经历和担任服务监督";
    [_textView addSubview:_label];
}

#pragma mark - uitextFeid的代理
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}


//将要开始编辑
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    //    if (Screen_H-64-_submitButton.bottom<216) {
    //        CGFloat hh = 216+30-(Screen_H-64-_submitButton.bottom);
    //        [UIView animateWithDuration:0.25 animations:^{
    //            self.view.center = CGPointMake(Screen_W/2, (Screen_H-64)/2-hh);
    //        }];
    //    }
    return YES;
}


#pragma mark UITextFieldDelegate-点击键盘的done收缩键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [_textView resignFirstResponder];
    
    return YES;
}


-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
        //        [UIView animateWithDuration:0.25 animations:^{
        //            self.view.center = CGPointMake(Screen_W/2, (Screen_H-64)/2);
        //        }];
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

/**
 *  监听textview
 *
 *  @param view _textview
 */
- (void)textViewEditChanged:(NSNotification *)notify {
    if ([notify.object isKindOfClass:[UITextView class]]) {
        UITextView *textView = notify.object;
        if (textView.text.length) {
            [_label setHidden:YES];
        }else{
            [_label setHidden:NO];
        }
    }
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
